<fieldset><legend>Filtros</legend>
<?php 	
	$this->Html->script(array('jquery.maskedinput-1.2.2.min','maskinput','jquery.ui.datepicker-pt-BR','datepicker'), false);
	$this->Html->css(array('agenda'), null, array('inline' => false));
	
	echo $this->Form->create('Agenda', array('target' => '_blank'));
	echo $this->Form->input('data_inicial', array('label' => __('Data Inicial'), 'type' => 'text', 'class' => 'maskdata data'));
	echo $this->Form->input('data_final', array('label' => __('Data Final'), 'type' => 'text', 'class' => 'maskdata data'));
	echo $this->Form->input('medico_id', array('label' => __('Médico'), 'type' => 'select', 'empty' => 'Todos',  'class' => 'tamanho50'));
	echo $this->Form->end();
?>
</fieldset>

<div id="horarios" style="background-color:white;padding:10px;border:1px solid #4682B4;border-radius:10px;display:none;"></div>

<script>

	$('#AgendaDataInicial,#AgendaDataFinal').change(function(){

		$.ajax({
			type: 'POST',
			url: root() + '/agendas/buscar_medicos_por_data/options',
			async: true,
			data: {
				data_inicial : $('#AgendaDataInicial').val(),
				data_final : $('#AgendaDataFinal').val()
			},
			beforeSend : function() {
				$('#AgendaMedicoId').html('<option>Carregando...</option>');
			},
			success: function(retorno){
				$('#AgendaMedicoId').html(retorno);
			}
		});	

	});

	$('.select_tipo_confirmacao').live('change',function(){
		var agenda_id = $(this).attr('id');
		var tipo_confirmacao_id = $(this).val();
		$.ajax({
			type: 'POST',
			url: root() + '/agendas/confirmacao_alterar/' + agenda_id + '/' + tipo_confirmacao_id,
			async: true,
			beforeSend : function() {
				$('#agenda_tr_'+agenda_id).css('opacity','0.4');
			},
			success: function(html){
				$('#agenda_tr_'+agenda_id).css('opacity','1');
			}
		});
	});

	$('#AgendaMedicoId').change(function(){
		carregar_horarios();
	});	

	function carregar_horarios() {

		$.ajax({
			type: 'POST',
			url: root() + '/agendas/confirmacao_lista/',
			async: true,
			data: $('#AgendaConfirmacaoForm').serialize(),
			beforeSend : function() {
				$('#horarios').show().css('opacity','0.4');
			},
			success: function(html){
				$('#horarios').html(html).css('opacity','1');
			}
		});
				
	}	

</script>	